﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using LibKetoan;
using System.Data;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmLogin.
	/// </summary>
	public class frmChuyenso : System.Windows.Forms.Form
	{
		private AccessData a;
		private int i_userid;
        bool btdcongno = false;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.NumericUpDown yyyy;
		private System.Windows.Forms.Button butOk;
		private System.Windows.Forms.Button butCancel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmChuyenso(AccessData acc,string mmyy,int userid)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;
			i_userid=userid;
			yyyy.Value=decimal.Parse("20"+mmyy.Substring(2,2));
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmChuyenso));
			this.label5 = new System.Windows.Forms.Label();
			this.yyyy = new System.Windows.Forms.NumericUpDown();
			this.butOk = new System.Windows.Forms.Button();
			this.butCancel = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.yyyy)).BeginInit();
			this.SuspendLayout();
			// 
			// label5
			// 
			this.label5.BackColor = System.Drawing.Color.Transparent;
			this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label5.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label5.Location = new System.Drawing.Point(60, 20);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(35, 20);
			this.label5.TabIndex = 0;
			this.label5.Text = "Năm :";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// yyyy
			// 
			this.yyyy.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.yyyy.Location = new System.Drawing.Point(95, 20);
			this.yyyy.Maximum = new System.Decimal(new int[] {
																 3004,
																 0,
																 0,
																 0});
			this.yyyy.Minimum = new System.Decimal(new int[] {
																 2004,
																 0,
																 0,
																 0});
			this.yyyy.Name = "yyyy";
			this.yyyy.Size = new System.Drawing.Size(50, 22);
			this.yyyy.TabIndex = 1;
			this.yyyy.Value = new System.Decimal(new int[] {
															   2004,
															   0,
															   0,
															   0});
			this.yyyy.KeyDown += new System.Windows.Forms.KeyEventHandler(this.yyyy_KeyDown);
			// 
			// butOk
			// 
			this.butOk.Image = ((System.Drawing.Bitmap)(resources.GetObject("butOk.Image")));
			this.butOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butOk.Location = new System.Drawing.Point(32, 59);
			this.butOk.Name = "butOk";
			this.butOk.Size = new System.Drawing.Size(68, 25);
			this.butOk.TabIndex = 2;
			this.butOk.Text = "      Đồng ý";
			this.butOk.Click += new System.EventHandler(this.butOk_Click);
			// 
			// butCancel
			// 
			this.butCancel.Image = ((System.Drawing.Bitmap)(resources.GetObject("butCancel.Image")));
			this.butCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butCancel.Location = new System.Drawing.Point(104, 59);
			this.butCancel.Name = "butCancel";
			this.butCancel.Size = new System.Drawing.Size(68, 25);
			this.butCancel.TabIndex = 3;
			this.butCancel.Text = "Kết thúc";
			this.butCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butCancel.Click += new System.EventHandler(this.butCancel_Click);
			// 
			// frmChuyenso
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(204, 105);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.butCancel,
																		  this.butOk,
																		  this.yyyy,
																		  this.label5});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmChuyenso";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Chuyển sổ";
			this.Load += new System.EventHandler(this.frmChuyenso_Load);
			((System.ComponentModel.ISupportInitialize)(this.yyyy)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion


		private void mm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");		
		}

		private void yyyy_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");
		}

		private void frmChuyenso_Load(object sender, System.EventArgs e)
		{
		
		}

		private void butCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void butOk_Click(object sender, System.EventArgs e)
		{
			string _tu="01"+yyyy.Value.ToString().PadLeft(4,'0').Substring(2,2);
			string _nam="20"+a.Mmyy_truoc(_tu).Substring(2);
			if (!a.bYyyy(_nam))
			{
				MessageBox.Show("Số liệu năm "+_nam+" chưa tạo !",a.Msg);
				return;
			}
			if (!a.bYyyy(yyyy.Value.ToString().PadLeft(4,'0')))
			{
				MessageBox.Show("Số liệu năm "+yyyy.Value.ToString().PadLeft(4,'0')+" chưa tạo !",a.Msg);
				return;
			}
			string s=a.KiemtraFb(_tu,_tu);
			if (s!="")
			{
				MessageBox.Show("Số liệu tháng :"+s.Substring(0,s.Length-1)+" Năm "+yyyy.Value.ToString().PadLeft(4,'0')+" bị khóa !");
				return;
			}
            else
            {
                a.updChuyenso(a.Mmyy_truoc(_tu), _tu, i_userid);
                if (btdcongno) a.chuyenctcn(a.Mmyy_truoc(_tu), _tu, i_userid);
                MessageBox.Show("Đã chuyển sổ năm " + yyyy.Value.ToString().PadLeft(4, '0') + " !", a.Msg);
            }
		}
	}
}
